// Kony


#include "AbilitySystem/ModMagCalc/MMC_MaxMana.h"

#include "AbilitySystem/BaseAttributeSet.h"
#include "Interaction/CombatInterface.h"

UMMC_MaxMana::UMMC_MaxMana()
{
	//获取体魄属性
	IntelligenceDef.AttributeToCapture = UBaseAttributeSet::GetIntelligenceAttribute();
	//获取属性捕获源
	IntelligenceDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;
	//设置快照
	IntelligenceDef.bSnapshot = false;
	//将属性定义添加到相关属性捕获列表中
	RelevantAttributesToCapture.Add(IntelligenceDef);

	SoulPowerDef.AttributeToCapture = UBaseAttributeSet::GetSoulPowerAttribute();
	SoulPowerDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;
	SoulPowerDef.bSnapshot = false;
	RelevantAttributesToCapture.Add(SoulPowerDef);
}

float UMMC_MaxMana::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{
	//从源和目标收集标签 Gather tags from source and target
	const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
	//目标获取
	const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();

	// 创建聚合器评估参数
	FAggregatorEvaluateParameters EvaluationParameters;
	// 设置源标签
	EvaluationParameters.SourceTags = SourceTags;
	// 设置目标标签
	EvaluationParameters.TargetTags = TargetTags;

	float Intelligence = 0.f;
	float SoulPower = 0.f;
	//获取目标上的 体魄属性值 写入到上面的 Vigor变量中
	GetCapturedAttributeMagnitude(IntelligenceDef, Spec, EvaluationParameters, Intelligence);
	GetCapturedAttributeMagnitude(SoulPowerDef, Spec, EvaluationParameters, SoulPower);
	Intelligence = FMath::Max<float>(Intelligence, 0.f); //设置如果小于0 则为0
	SoulPower = FMath::Max<float>(SoulPower, 0.f); //设置如果小于0 则为0
	
	//获取源对象 战斗接口
	int32 PlayerLevel = 1;
	if (Spec.GetContext().GetSourceObject()->Implements<UCombatInterface>())
	{
		//获取等级
		PlayerLevel = ICombatInterface::Execute_GetPlayerLevel(Spec.GetContext().GetSourceObject());
	}
	// 这是旧版获取
	// ICombatInterface* CombatInterface = Cast<ICombatInterface>(Spec.GetContext().GetSourceObject());
	
	
	//返回 根据公式计算后的 最大生命值
	return 50.f + 1.f * Intelligence + 0.5f * SoulPower + 15.f * PlayerLevel;
}
